//
//  XSJMainViewController.swift
//  weiBo项目准备
//
//  Created by 鲜世杰 on 16/5/10.
//  Copyright © 2016年 鲜世杰. All rights reserved.
//

import UIKit

import SVProgressHUD

class XSJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let XSJTabBar = XSJUITabBar()
        XSJTabBar.XSJDelegate = self

        XSJTabBar.composeButtonClousre = { [weak self] in


            if XSJUserAccountViewModel.sharedUserAccount.isLogin {
            
                self?.showComposeVC()
              
            }else{
            
                SVProgressHUD.showErrorWithStatus("您未登录,请先登录!")
                
            }
            
        }
        setValue(XSJTabBar, forKey: "tabBar")
        
        
        

        addChildViewController(XSJHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(XSJMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(XSJDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(XSJProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    
    private func showComposeVC() {
        
        let composeVc = XSJComposeViewController()
        
        let comoposeNav = UINavigationController(rootViewController: composeVc)
        
        presentViewController(comoposeNav, animated: true, completion: nil)
        
    }

    
        func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        UITabBar.appearance().tintColor = UIColor.orangeColor()
            childController.tabBarItem.title = title
            childController.navigationItem.title = title
            childController.title = title
            childController.tabBarItem.image = UIImage(named: imageName)
            childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
//            childController.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
            childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :UIColor .orangeColor()], forState: .Selected)
            childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont .systemFontOfSize(14)], forState: .Normal)
            let nav = UINavigationController(rootViewController: childController)
            addChildViewController(nav)
        
        
    }
    
    
    
}

extension XSJMainViewController: XSJTabBarDelegate {
    func didSelectedComposeButton() {
        
    }
}
